// 属性列表
controllers.controller('returnGoodsOrderCtrl', ['$scope', '$http', '$rootScope', '$modal', '$window', 'ReturnGoodsOrder', 'AlertService',
    function ($scope, $http, $rootScope, $modal, $window, ReturnGoodsOrder, AlertService) {
        $scope.resetCurrentPageName("退货订单管理");
        $scope.pageSize = 20;
        $scope.currentPage = 1;
        $scope.returnGoodsOrderList = ReturnGoodsOrder.returnGoodsOrderList;
        $scope.returnGoodsOrder;
        $scope.disburseNo;
        $scope.status;
        $scope.currentProperty = ReturnGoodsOrder.currentProperty;

        $scope.queryList = function () {
        	ReturnGoodsOrder.queryList($scope.disburseNo, $scope.returnGoodsNo, $scope.startDate, $scope.endDate, $scope.status, $scope.currentPage, $scope.pageSize, function () {
                $scope.totalItems = ReturnGoodsOrder.totalSceneCount;
            });
        };
        
        $scope.confirmRechargeOrder = function (rechargeOrderNo) {
        	RechargeOrder.confirmRechargeOrder(rechargeOrderNo, function () {
            });
        };
        
        $scope.agreeReturnGoods = function (returnGoodsOrder) {

        	ReturnGoodsOrder.currentReturnGoodsOrder = returnGoodsOrder;
            $rootScope.contextIsModal = true;
            $rootScope.modalIns = $modal.open({
                templateUrl: './partials/order/agreeReturnGoods.html',
                animation: true,
                controller: 'agreeReturnGoodsCtrl',
                windowClass: 'app-modal-window',
                size: 'lg',
                resolve: {}
            });
            $rootScope.ok = function () {
                //callback();
                $rootScope.modalIns.dismiss();
            };
            $rootScope.cancel = function () {
                $rootScope.modalIns.dismiss();
            };
            $rootScope.modalIns.result.then(function () {
                $rootScope.contextIsModal = false;

            }, function () {
                $rootScope.contextIsModal = false;
            });

        };
        
        $scope.queryList();

        var operateTemplate = "<div ng-if='row.entity.status == 1'><button class='btn btn-primary btn-sm' ng-click='grid.appScope.agreeReturnGoods(row.entity)'>同意</button></div>";

        $scope.gridOptions = {
            data: 'returnGoodsOrderList',
            enableColumnMenus: false,
            enableColumnResizing: true,
            rowHeight: 40,
            columnDefs: [
                {field: 'returnGoodsNo', displayName: '退货订单号', width: 200},
                {field: 'disburseNo', displayName: '消费订单号', width: 200},
                {field: 'itemId', displayName: '商品ID', width: 100},
                {field: 'remark', displayName: '商品单价', width: 100},
                {field: 'quantity', displayName: '商品数量', width: 100},
                {field: 'rate', displayName: '费率', width: 50},
                {field: 'logisticsCompany', displayName: '物流公司', width: 80},
                {field: 'logisticsNo', displayName: '物流单号', width: 80},
                {field: 'refundAmount', displayName: '退款金额', width: 100},
                {field: 'statusName', displayName: '状态', width: 80},
                {field: 'timeAddStr', displayName: '添加时间', width: 120},
                {field: 'timeEditStr', displayName: '修改时间', width: 120},
                {
                    field: 'id',
                    displayName: '操作',
                    width: "200",
                    cellTemplate: operateTemplate
                }
            ]
        };
    }]);


//更新订单
controllers.controller('agreeReturnGoodsCtrl', ['$scope', '$rootScope', '$window', '$modal', 'ReturnGoodsOrder', 'AlertService',
    function ($scope, $rootScope, $window, $modal, ReturnGoodsOrder, AlertService) {
        $scope.resetCurrentPageName("退货管理");
        $scope.currentReturnGoodsOrder = ReturnGoodsOrder.currentReturnGoodsOrder;


        $scope.sendGoods = function (returnGoodsOrder) {

        	ReturnGoodsOrder.agreeReturnGoods($scope.currentReturnGoodsOrder, function () {
                AlertService.addAlert({type: 'success', msg: '成功! '}, 1000);
                //$window.location.href = "#tran/disburseList";
                //上下文放到这里
                //$rootScope.selectedItemList = [];
                $rootScope.ok();
            });
            //回调函数

        };


    }]);
